import os

from pydantic import computed_field
from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
    PROJECT_NAME: str = "Treasure"
    PROJECT_PORT: int = 8000

    API_V1_STR: str = "/api/v1"

    MYSQL_USER: str
    MYSQL_PASSWORD: str
    MYSQL_HOST: str
    MYSQL_PORT: int
    MYSQL_DB: str
    MYSQL_CHARSET: str

    LOG_DIR: str
    LOG_ROTATION: str
    LOG_FORMATE: str

    @computed_field
    @property
    def DATABASE_URL(self) -> str:
        return f"mysql+aiomysql://{self.MYSQL_USER}:{self.MYSQL_PASSWORD}@{self.MYSQL_HOST}:{self.MYSQL_PORT}/{self.MYSQL_DB}?charset={self.MYSQL_CHARSET}"

    model_config = SettingsConfigDict(env_file=os.path.normpath(os.path.join(os.path.dirname(__file__), "../.env")))


settings = Settings()